Simplify surface move/drag api
authorMatthias Clasen <mclasen@redhat.com>
Sat, 29 Feb 2020 16:25:32 +0000 (11:25 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 11 Mar 2020 23:35:55 +0000 (19:35 -0400)
Drop the with_device variants, and always pass a device.

gdk/gdksurface.c
gdk/gdksurface.h
gtk/gtkwindow.c
tests/testwindowdrag.c

index 8c9a23db10f698bbb726680c28a3e30e8bf3143e..76aedf90a250144043f87215d88d4bcf7aff0a48 100644 (file)
@@ -3408,7 +3408,7 @@ gdk_surface_set_functions (GdkSurface    *surface,
 }
 
 /**
- * gdk_surface_begin_resize_drag_for_device:
+ * gdk_surface_begin_resize_drag:
  * @surface: a toplevel #GdkSurface
  * @edge: the edge or corner from which the drag is started
  * @device: the device used for the operation
@@ -3421,95 +3421,55 @@ gdk_surface_set_functions (GdkSurface    *surface,
  * You might use this function to implement a “window resize grip,”
  */
 void
-gdk_surface_begin_resize_drag_for_device (GdkSurface     *surface,
-                                          GdkSurfaceEdge  edge,
-                                          GdkDevice      *device,
-                                          gint            button,
-                                          gint            x,
-                                          gint            y,
-                                          guint32         timestamp)
-{
-  GDK_SURFACE_GET_CLASS (surface)->begin_resize_drag (surface, edge, device, button, x, y, timestamp);
-}
-
-/**
- * gdk_surface_begin_resize_drag:
- * @surface: a toplevel #GdkSurface
- * @edge: the edge or corner from which the drag is started
- * @button: the button being used to drag, or 0 for a keyboard-initiated drag
- * @x: surface X coordinate of mouse click that began the drag
- * @y: surface Y coordinate of mouse click that began the drag
- * @timestamp: timestamp of mouse click that began the drag (use gdk_event_get_time())
- *
- * Begins a surface resize operation (for a toplevel surface).
- *
- * This function assumes that the drag is controlled by the
- * client pointer device, use gdk_surface_begin_resize_drag_for_device()
- * to begin a drag with a different device.
- */
-void
 gdk_surface_begin_resize_drag (GdkSurface     *surface,
                                GdkSurfaceEdge  edge,
+                               GdkDevice      *device,
                                gint            button,
                                gint            x,
                                gint            y,
                                guint32         timestamp)
 {
-  GdkDevice *device;
-
-  device = gdk_seat_get_pointer (gdk_display_get_default_seat (surface->display));
-  gdk_surface_begin_resize_drag_for_device (surface, edge,
-                                            device, button, x, y, timestamp);
-}
+  if (device == NULL)
+    {
+      GdkSeat *seat = gdk_display_get_default_seat (surface->display);
+      if (button == 0)
+        device = gdk_seat_get_keyboard (seat);
+      else
+        device = gdk_seat_get_pointer (seat);
+    }
 
-/**
- * gdk_surface_begin_move_drag_for_device:
- * @surface: a toplevel #GdkSurface
- * @device: the device used for the operation
- * @button: the button being used to drag, or 0 for a keyboard-initiated drag
- * @x: surface X coordinate of mouse click that began the drag
- * @y: surface Y coordinate of mouse click that began the drag
- * @timestamp: timestamp of mouse click that began the drag
- *
- * Begins a surface move operation (for a toplevel surface).
- */
-void
-gdk_surface_begin_move_drag_for_device (GdkSurface *surface,
-                                        GdkDevice  *device,
-                                        gint        button,
-                                        gint        x,
-                                        gint        y,
-                                        guint32     timestamp)
-{
-  GDK_SURFACE_GET_CLASS (surface)->begin_move_drag (surface,
-                                                    device, button, x, y, timestamp);
+  GDK_SURFACE_GET_CLASS (surface)->begin_resize_drag (surface, edge, device, button, x, y, timestamp);
 }
 
 /**
  * gdk_surface_begin_move_drag:
  * @surface: a toplevel #GdkSurface
+ * @device: the device used for the operation
  * @button: the button being used to drag, or 0 for a keyboard-initiated drag
  * @x: surface X coordinate of mouse click that began the drag
  * @y: surface Y coordinate of mouse click that began the drag
  * @timestamp: timestamp of mouse click that began the drag
  *
  * Begins a surface move operation (for a toplevel surface).
- *
- * This function assumes that the drag is controlled by the
- * client pointer device, use gdk_surface_begin_move_drag_for_device()
- * to begin a drag with a different device.
  */
 void
 gdk_surface_begin_move_drag (GdkSurface *surface,
-                             gint       button,
-                             gint       x,
-                             gint       y,
-                             guint32    timestamp)
+                             GdkDevice  *device,
+                             gint        button,
+                             gint        x,
+                             gint        y,
+                             guint32     timestamp)
 {
-  GdkDevice *device;
+  if (device == NULL)
+    {
+      GdkSeat *seat = gdk_display_get_default_seat (surface->display);
+      if (button == 0)
+        device = gdk_seat_get_keyboard (seat);
+      else
+        device = gdk_seat_get_pointer (seat);
+    }
 
-  device = gdk_seat_get_pointer (gdk_display_get_default_seat (surface->display));
-  gdk_surface_begin_move_drag_for_device (surface, device, button, x, y, timestamp);
+  GDK_SURFACE_GET_CLASS (surface)->begin_move_drag (surface, device, button, x, y, timestamp);
 }
 
 /**
index 67ba05b4aeb23ac381947fc1731ccf35f5690578..5d796d950832243c3dfad5a9f026627e0b472682 100644 (file)
@@ -539,27 +539,15 @@ void          gdk_surface_set_opacity     (GdkSurface       *surface,
 
 GDK_AVAILABLE_IN_ALL
 void gdk_surface_begin_resize_drag            (GdkSurface     *surface,
-                                               GdkSurfaceEdge  edge,
-                                               gint            button,
-                                               gint            x,
-                                               gint            y,
-                                               guint32         timestamp);
-GDK_AVAILABLE_IN_ALL
-void gdk_surface_begin_resize_drag_for_device (GdkSurface     *surface,
                                                GdkSurfaceEdge  edge,
                                                GdkDevice      *device,
                                                gint            button,
                                                gint            x,
                                                gint            y,
                                                guint32         timestamp);
+
 GDK_AVAILABLE_IN_ALL
 void gdk_surface_begin_move_drag              (GdkSurface     *surface,
-                                               gint            button,
-                                               gint            x,
-                                               gint            y,
-                                               guint32         timestamp);
-GDK_AVAILABLE_IN_ALL
-void gdk_surface_begin_move_drag_for_device   (GdkSurface     *surface,
                                                GdkDevice      *device,
                                                gint            button,
                                                gint            x,
index f598e905ee45a6ee77bd6507ab943774f1451cbc..ee054a20c3264d7441a2d075aa0f7092fd5b74ce 100644 (file)
@@ -1428,12 +1428,12 @@ click_gesture_pressed_cb (GtkGestureClick *gesture,
           gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
 
           gdk_event_get_position (event, &tx, &ty);
-          gdk_surface_begin_resize_drag_for_device (priv->surface,
-                                                   (GdkSurfaceEdge) region,
-                                                   gdk_event_get_device ((GdkEvent *) event),
-                                                   GDK_BUTTON_PRIMARY,
-                                                   tx, ty,
-                                                   gdk_event_get_time (event));
+          gdk_surface_begin_resize_drag (priv->surface,
+                                         (GdkSurfaceEdge) region,
+                                         gdk_event_get_device ((GdkEvent *) event),
+                                         GDK_BUTTON_PRIMARY,
+                                         tx, ty,
+                                         gdk_event_get_time (event));
 
           gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
           gtk_event_controller_reset (GTK_EVENT_CONTROLLER (priv->drag_gesture));
@@ -1529,11 +1529,11 @@ drag_gesture_update_cb (GtkGestureDrag *gesture,
 
       gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y);
 
-      gdk_surface_begin_move_drag_for_device (priv->surface,
-                                             gtk_gesture_get_device (GTK_GESTURE (gesture)),
-                                             gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)),
-                                             (int)start_x, (int)start_y,
-                                             gtk_get_current_event_time ());
+      gdk_surface_begin_move_drag (priv->surface,
+                                   gtk_gesture_get_device (GTK_GESTURE (gesture)),
+                                   gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)),
+                                   (int)start_x, (int)start_y,
+                                   gtk_get_current_event_time ());
 
       gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
       gtk_event_controller_reset (GTK_EVENT_CONTROLLER (priv->click_gesture));
@@ -6688,6 +6688,7 @@ move_window_clicked (GtkModelButton *button,
   GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
 
   gdk_surface_begin_move_drag (priv->surface,
+                               NULL,
                                0, /* 0 means "use keyboard" */
                                0, 0,
                                GDK_CURRENT_TIME);
@@ -6702,6 +6703,7 @@ resize_window_clicked (GtkModelButton *button,
 
   gdk_surface_begin_resize_drag (priv->surface,
                                  0,
+                                 NULL,
                                  0, /* 0 means "use keyboard" */
                                  0, 0,
                                  GDK_CURRENT_TIME);
index 90dc9766b6636a413ab36e79020a203e1570c0ce..e25abf0cefe13613b7c22e7c28b13d65dfb625e0 100644 (file)
@@ -28,7 +28,7 @@ start_resize (GtkGestureClick *gesture,
 
   gtk_widget_translate_coordinates (widget, GTK_WIDGET (gtk_widget_get_root (widget)),
                                     xx, yy, &xx, &yy);
-  gdk_surface_begin_resize_drag (surface, edge, button, xx, yy, timestamp);
+  gdk_surface_begin_resize_drag (surface, edge, gdk_event_get_device (event), button, xx, yy, timestamp);
 
   gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
 }
@@ -76,7 +76,7 @@ start_move (GtkGestureClick *gesture,
 
   gtk_widget_translate_coordinates (widget, GTK_WIDGET (gtk_widget_get_root (widget)),
                                     xx, yy, &xx, &yy);
-  gdk_surface_begin_move_drag (surface, button, xx, yy, timestamp);
+  gdk_surface_begin_move_drag (surface, gdk_event_get_device (event), button, xx, yy, timestamp);
   gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
 }